using System;
using Mvvm;

namespace LayoutPlanning.Model
{
    [Serializable]
    public class StationRelation : BindableBase
    {
        private Station _station1;
        private Station _station2;
        private double _value = 0;

        public StationRelation()
        {
        }

        public StationRelation(Station source, Station loud, double loudness)
        {
            Station1 = source;
            Station2 = loud;
            Value = loudness;
        }

        public Station Station1
        {
            get { return _station1; }
            set
            {
                _station1 = value;
                _station1.PropertyChanged += _station_PropertyChanged;
                RaisePropertyChanged();
            }
        }

        public Station Station2
        {
            get { return _station2; }
            set
            {
                _station2 = value;
                _station2.PropertyChanged += _station_PropertyChanged;
                RaisePropertyChanged();
            }
        }

        public double Value
        {
            get { return _value; }
            set
            {
                _value = value;

                RaisePropertyChanged();
            }
        }

        private void _station_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(Station1.Position) && sender == Station1)
                RaisePropertyChanged("Station1");
            if (e.PropertyName == nameof(Station2.Position) && sender == Station2)
                RaisePropertyChanged("Station2");
        }
    }
}